<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {
	//构造函数
	public function __construct(){
		parent::__construct();
		$this->load->model('user_model','user');
		$this->load->model('hire_model','hire');
		$this->load->library('session');//加载资源文件
	}
	/*
	 * 用户个人中心
	 * */
	public function index(){
		$jsonp = $_GET["callback"];
		$username = $this->session->userdata('user_id');
		$re = $this->user->row(array('id' => $username));
		if($re){
			$data['status'] = 1;
			$data['user_name'] = $re['user_name'];
		}else{
			$data['status'] = 0;
		}
		echo $jsonp."(".json_encode($data).")";
	}
	
	/*
	 * 密码修改
	 * */
	public function change_password(){
		$jsonp = $_GET["callback"];
		$password = $_GET["password"];
		$new_password = $_GET["new_password"];
		$new_password_to = $_GET["new_password_to"];
		$user_name= $this->session->userdata('user_id');
		if(!$this->admin->noJiaAdminUserPwd($user_name,$password)){
			$data['status'] = 0;
		}else{
			if($new_password != $new_password_to){
				$data['status'] = 2;
			}else{
				$re = $this->admin->noJiaChangePwd($user_name,$new_password);
				if($re){
					$data['status'] = 1;
				}
			}
		}
		echo $jsonp."(".json_encode($data).")";
	}
	/*
	 * 查看回复
	 * */
	public function getHire(){
		$jsonp = $_GET["callback"];
		$user_name= $this->session->userdata('user_name');
		$data['message'] = $this->hire->resultAll(array('user' => $user_name));
		if(!empty($data['message'])){
			$data['status'] = 1;
		}
		echo $jsonp."(".json_encode($data).")";
	}
}